package com.hdkj.oss.controller;

import com.hdkj.commonutils.R;
import com.hdkj.oss.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Api(description = "阿里云oss文件上传")
@RestController
@RequestMapping("/edu/fileoss")
//解决跨域
//@CrossOrigin

public class osscontroller {
    @Autowired
    private OssService ossService;

    @PostMapping("upfile")
    public R upfile(MultipartFile file){
        String url = ossService.upfileByoss(file);
        return R.ok().data("url",url);
    }

    @ApiOperation(value = "文件删除")
    @DeleteMapping("remove")
    public R removeFile(
            @ApiParam(value = "要删除的文件url路径", required = true)
            @RequestBody String url){
        ossService.removeFile(url);
        return R.ok().message("文件删除成功");
    }

}
